package service;

import dao.DeptMapper;
import entity.DeptEntity;
import org.apache.ibatis.session.SqlSession;
import util.SqlSessionFactoryUtil;

import java.util.List;

public class DeptServiceImpl {
    // 添加方法
    public void insert() {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            DeptMapper mapper = sqlSession.getMapper(DeptMapper.class);
            mapper.insert();
        }
    }

    // 删除方法
    public void delete(int id) {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            DeptMapper mapper = sqlSession.getMapper(DeptMapper.class);
            mapper.deleteById(13);
        }
    }

    // 查询所有信息方法
    public List<DeptEntity> getAll() {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            DeptMapper mapper = sqlSession.getMapper(DeptMapper.class);
            return mapper.getAll();
        }
    }

    // 根据编号查询信息方法
    public DeptEntity getById(int id) {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            DeptMapper mapper = sqlSession.getMapper(DeptMapper.class);
            return mapper.getById(id);
        }
    }

    // 修改方法
    public void update(int id) {
        try (SqlSession sqlSession = SqlSessionFactoryUtil.getSession()){
            DeptMapper mapper = sqlSession.getMapper(DeptMapper.class);
            mapper.update(id);
        }
    }
}
